/***************************************************************
*  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
*  All rights reserved
*
*  This file is part of the GroupMe! Project. You can utilize
*  software of the GroupMe! project under the terms of the 
*  GNU Lesser General Public License as published by the
*  Free Software Foundation in version 2.1.
* 
*  The GNU Lesser General Public License can be found at:
*  http://www.gnu.org/licenses/lgpl.html
*
*  This copyright notice MUST APPEAR in all copies of the file!
***************************************************************/
package net.groupme.export;

import java.util.Collection;
import net.groupme.model.Group;
import net.groupme.model.ObjectFactoryProperties;
import net.groupme.model.Resource;
import net.groupme.model.Tag;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 *
 * @author Daniel Plappert
 * @version 0.1
 */
public abstract class AbstractExporter implements IExporter {

    
    /** the data source (= backend for DAO implementation) */
    static DriverManagerDataSource ds = new DriverManagerDataSource();
    static {
        ds.setDriverClassName(ObjectFactoryProperties.getString("ObjectFactoryProperties.DB_DRIVER")); //$NON-NLS-1$
        ds.setUrl(ObjectFactoryProperties.getString("ObjectFactoryProperties.DB_URL")); //$NON-NLS-1$
        ds.setUsername(ObjectFactoryProperties.getString("ObjectFactoryProperties.DB_USER")); //$NON-NLS-1$
        ds.setPassword(ObjectFactoryProperties.getString("ObjectFactoryProperties.DB_PW")); //$NON-NLS-1$
    }    
    
    protected boolean exportUser = false;
    protected Collection<Group> groupData = null;
    protected Collection<Resource> resourceData = null;
    private boolean exportGroupById = false;
    private boolean exportResourceById = false;
    protected Collection<Tag> keywords = null;
    
    /** Creates a new instance of AbstractExporter */
    public AbstractExporter() {
    }
    
    
    
    /**
     *
     *
     * @param Collection<Group>
     */
    public void setGroupData(Collection<Group> data) {
        groupData = data;
    }
    
    
    /**
     * 
     *
     * @param Collection<Resource>
     */
    public void setResourceData(Collection<Resource> data) {
        resourceData = data;
    }
    
    
    /**
     *
     *
     * @param boolean
     */
    public void setExportUser(boolean value) {
        exportUser = value;
    }    
    
    
    /**
     *
     *
     * @param int ID
     */
    public void setGroupDataByGroupId(int id) {
        setGroupExportedById(true);
        setResourceExportedById(false);
        setGroupData(Utils.getGroupsByGroupId(ds, id));        
    }
    
    
    /**
     *
     * 
     * @param int ID
     */
    public void setResourceDataByResourceId(int id) {
        setGroupExportedById(false);
        setResourceExportedById(true);
        setResourceData(Utils.getResourcesByResourceId(ds, id));
    }    
    
   
    /**
     *
     * 
     * @param int ID
     */
    public void setDataByUserId(int id) {
        setGroupData(Utils.getGroupDataByUserId(ds, id));
    } 
    
    
    /**
     *
     *
     *
     */
    protected boolean resourceIsExportedById() {
        return exportResourceById;
    }
    
    
    /**
     *
     *
     *
     */
    protected boolean groupIsExportedById() {
        return exportGroupById;
    }
        
    
    /**
     *
     *
     * @param <ollection<Tag>
     */
    public void setUsedKeywords(Collection<Tag> tagCollection) {
        this.keywords = tagCollection;
    }
    
    
    /**
     *
     *
     */
    private void setGroupExportedById(boolean value) {
        exportGroupById = value;
    }
    
    
    /**
     *
     *
     */
    private void setResourceExportedById(boolean value) {
        exportResourceById = value;
    }
    
}
